package com.demo.controller;

import com.demo.common.Result;
import com.demo.service.ScheduleStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 排课统计控制器
 */
@RestController
@RequestMapping("/statistics")
@CrossOrigin
public class ScheduleStatisticsController {
    
    @Autowired
    private ScheduleStatisticsService scheduleStatisticsService;
    
    /**
     * 获取教室利用率统计
     */
    @GetMapping("/classroom-utilization/{semester}")
    public Result<Map<String, Object>> getClassroomUtilizationStats(@PathVariable String semester) {
        try {
            Map<String, Object> stats = scheduleStatisticsService.getClassroomUtilizationStats(semester);
            return Result.success(stats);
        } catch (Exception e) {
            return Result.error("获取教室利用率统计失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取教师工作量统计
     */
    @GetMapping("/teacher-workload/{semester}")
    public Result<Map<String, Object>> getTeacherWorkloadStats(@PathVariable String semester) {
        try {
            Map<String, Object> stats = scheduleStatisticsService.getTeacherWorkloadStats(semester);
            return Result.success(stats);
        } catch (Exception e) {
            return Result.error("获取教师工作量统计失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取课程分布统计
     */
    @GetMapping("/course-distribution/{semester}")
    public Result<Map<String, Object>> getCourseDistributionStats(@PathVariable String semester) {
        try {
            Map<String, Object> stats = scheduleStatisticsService.getCourseDistributionStats(semester);
            return Result.success(stats);
        } catch (Exception e) {
            return Result.error("获取课程分布统计失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取排课质量分析
     */
    @GetMapping("/schedule-quality/{semester}")
    public Result<Map<String, Object>> getScheduleQualityAnalysis(@PathVariable String semester) {
        try {
            Map<String, Object> analysis = scheduleStatisticsService.getScheduleQualityAnalysis(semester);
            return Result.success(analysis);
        } catch (Exception e) {
            return Result.error("获取排课质量分析失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取冲突统计
     */
    @GetMapping("/conflict-stats/{semester}")
    public Result<Map<String, Object>> getConflictStats(@PathVariable String semester) {
        try {
            Map<String, Object> stats = scheduleStatisticsService.getConflictStats(semester);
            return Result.success(stats);
        } catch (Exception e) {
            return Result.error("获取冲突统计失败：" + e.getMessage());
        }
    }
}
























